/*****************************************************************************
 *
 *                      HUSONG PROPRIETARY INFORMATION
 *
 *          The information contained herein is proprietary to HUSONG
 *           and shall not be reproduced or disclosed in whole or in part
 *                    or used for any design or manufacture
 *              without direct written authorization from HUSONG.
 *
 *            Copyright (c) 2015 by HUSONG.  All rights reserved.
 *
 *****************************************************************************/
package me.send.broker.mapper;

import java.util.Map;

import org.apache.ibatis.annotations.Select;

import me.send.broker.entity.User;

/**
 * @author maxmin
 *
 * @date 2015年8月25日 下午4:17:05
 */
public interface UserMapper {
	
	/**
	 * 获取用户信息
	 * @param userId
	 * @return
	 * @author maxmin
	 * @date 2015年8月25日下午5:30:49
	 */
	@Select(value = "SELECT u.userid,u.headerpath,u.nickname,u.sex,"
			+ "(SELECT IF(COUNT(1)>0,SUM(ue.point)/COUNT(ue.point),0)  FROM user_evaluate ue LEFT JOIN orders o ON o.orderid = ue.orderid AND o.userid = #{userId}) stars "
			+ "FROM `user` u WHERE u.userid=#{userId}")
	public User getUserInfoById(int userId);
	
	
	@Select(value = "SELECT u.userid,u.headerpath,u.nickname,u.sex,u.telephone,"
			+ "(SELECT IF(COUNT(1)>0,SUM(ue.point)/COUNT(ue.point),0)  FROM user_evaluate ue LEFT JOIN orders od ON od.orderid = ue.orderid "
			+ "LEFT JOIN `user` us ON od.userid = us.userid WHERE us.userid=u.userid) stars  "
			+ "FROM `user` u LEFT JOIN orders o ON o.userid = u.userid WHERE o.orderid=#{orderid}")
	public Map<String, Object> getUserByOrderId(int orderid);
}
